﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace Dragoon
{
    public class GameBase : Microsoft.Xna.Framework.Game
    {
        protected GraphicsDeviceManager graphics;
        public GameBase()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            const int size = 500;
            if (size > 0)
            {
                graphics.PreferredBackBufferWidth = size;
                graphics.PreferredBackBufferHeight = size;
                graphics.IsFullScreen = false;
            }
            else
                graphics.IsFullScreen = true;
            graphics.ApplyChanges();
            base.Initialize();
        }

        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().GetPressedKeys().Contains(Keys.F12))
                Screenshot();
            base.Update(gameTime);
        }

        private void Screenshot()
        {
            using (
                ResolveTexture2D screenshot = new ResolveTexture2D(
                   graphics.GraphicsDevice,
                   graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
                   graphics.GraphicsDevice.PresentationParameters.BackBufferHeight,
                   1, SurfaceFormat.Color))
            {
                GraphicsDevice.ResolveBackBuffer(screenshot);

                screenshot.Save("screenshot.jpg", ImageFileFormat.Jpg);
            }
        }
    }
}
